<HTML>

<HEAD>
        <META NAME="keywords" CONTENT="electronic commerce, ecommerce, ebusiness, e-business, e-commerce, enterprise software, net economy, Netscape, Sun Microsystems, Sun-Netscape Alliance, iPlanet, internet software">
        <META NAME="description" CONTENT="The Sun-Netscape Alliance, a strategic alliance formed by America Online and Sun Microsystems, Inc., is delivering iPlanet e-commerce software and enterprise solutions that enable companies to compete successfully in the Net Economy">
	<META HTTP-EQUIV="Content-Type" content="text/html; charset=ISO-8859-1">
	<META NAME="TEMPLATEBASE" CONTENT="Authored in FrameMaker. Converted to HTML in WebWorks Publisher 2000. manual wdt 1.5">
	<META NAME="LASTUPDATED" CONTENT="09/28/00 13:18:06">
	<TITLE> Core JavaScript Guide 1.5: 9 LiveConnect Overview</TITLE>
</HEAD>




<BODY TEXT="#000000" LINK="#666699" VLINK="#666699" ALINK="#333366" BGCOLOR="#FFFFFF">

<MAINCONTENT>

<NAVIGATIONCONTENT>
   <TABLE WIDTH="100%" BORDER="0" CELLSPACING="4">
      <TR>
         <TD VALIGN="TOP">
            <b><a href="partlc.html">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Previous</a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;</b>
<a href="contents.html">
<b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Contents</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="ix.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Index</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="glossary.html">
<b>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">
Next
</a>
</FONT>
</b>&nbsp;&nbsp;&nbsp;&nbsp;
         </TD>
     </TR>

      <TR>
         <TD VALIGN="TOP" ALIGN="RIGHT" BGCOLOR="#CCCCCC">
            <FONT FACE="Arial, Helvetica, sans-serif" COLOR="#000000" SIZE="2"><B>
             Core JavaScript Guide 1.5</B></FONT>
         </TD>
      </TR>
      <TR>
   </TABLE>
   <BR>
</NAVIGATIONCONTENT>

<BOOKCONTENT>
   <blockquote>
<BR>
<BR>

      <A NAME="1008300"> </A><A NAME=""> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4" COLOR="#666666"><B>
<zchapnumber>Chapter 9 </zchapnumber>
&nbsp;
</B>
</FONT>


<A NAME="1008305"> </A>
<A NAME="LiveConnect Overview"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4" COLOR="#000000">
<B>
<zchaptitle>LiveConnect Overview</zchaptitle>
</B>
</FONT>
<BR>
<BR>
<BR>

<A NAME="1021579"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This chapter describes using LiveConnect technology to let Java and JavaScript code communicate with each other. The chapter assumes you are familiar with Java programming.</zparagraph>
</FONT>
<P>

<A NAME="1015012"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This chapter contains the following sections:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1039521"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1013074"  >Working with Wrappers</A></zsmartlist1>
</FONT>
<P><A NAME="1015024"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1014290"  >JavaScript to Java Communication</A></zsmartlist1>
</FONT>
<P><A NAME="1015028"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1008480"  >Java to JavaScript Communication</A></zsmartlist1>
</FONT>
<P><A NAME="1037588"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037078"  >Data Type Conversions</A></zsmartlist1>
</FONT>
<P></ul>

<A NAME="1021561"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For additional information on using LiveConnect, see the <A HREF="http://developer.netscape.com/docs/technote/index.html">JavaScript technical notes</A> on the DevEdge site.</zparagraph>
</FONT>
<P>

<BR>
<BR>

<A NAME="1013074"> </A>
<A NAME="Working with Wrappers"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>Working with Wrappers</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1036886"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In JavaScript, a <I>wrapper</I> is an object of the target language data type that encloses an object of the source language. When programming in JavaScript, you can use a wrapper object to access methods and fields of the Java object; calling a method or accessing a property on the wrapper results in a call on the Java object. On the Java side, JavaScript objects are wrapped in an instance of the class <FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSObject</FONT> and passed to Java.</zparagraph>
</FONT>
<P>

<A NAME="1036887"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT>; when a <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT> is sent from Java to JavaScript, the runtime engine unwraps it to its original JavaScript object type. The <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT> class provides an interface for invoking JavaScript methods and examining JavaScript properties.</zparagraph>
</FONT>
<P>

<BR>
<BR>

<A NAME="1014290"> </A>
<A NAME="JavaScript to Java Communication"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>JavaScript to Java Communication</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1028815"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you refer to a Java package or class, or work with a Java object or array, you use one of the special LiveConnect objects. All JavaScript access to Java takes place with these objects, which are summarized in the following table.</zparagraph>
</FONT>
<P>

<A NAME="1040657"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B>
<A NAME="1040692"> </A>
<A NAME="The LiveConnect Objects"> </A>
<ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablecaption>Table 9.1&#32;&nbsp&nbsp The LiveConnect Objects</ztablecaption>
</B>
</FONT>
</B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1040696"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Object</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1040698"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Description</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1040738"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">JavaArray</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1040740"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A wrapped Java array, accessed from within JavaScript code.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1040743"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1040745"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A JavaScript reference to a Java class.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1040748"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">JavaObject</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1040750"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A wrapped Java object, accessed from within JavaScript code.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1040753"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">JavaPackage</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1040755"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A JavaScript reference to a Java package.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
</TABLE>



<P></zparagraph>
</FONT>
<P>

<A NAME="1029095"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<znote>Note</znote>
</B>
</FONT>


<A NAME="1037474"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Because Java is a strongly typed language and JavaScript is weakly typed, the JavaScript runtime engine converts argument values into the appropriate data types for the other language when you use LiveConnect. See <A HREF="lc.html#1037078"  >Data Type Conversions</A> for complete information.</zparagraph>
</FONT>
<P>

<A NAME="1037469"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In some ways, the existence of the LiveConnect objects is transparent, because you interact with Java in a fairly intuitive way. For example, you can create a Java <FONT FACE="courier, couriernew, monospaced size">String</FONT> object and assign it to the JavaScript variable <FONT FACE="courier, couriernew, monospaced size">myString</FONT> by using the <FONT FACE="courier, couriernew, monospaced size">new</FONT> operator with the Java constructor, as follows:</zparagraph>
</FONT>
<P>
<A NAME="1028973"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>var myString = new java.lang.String("Hello world")
</zcodeline>
</FONT>
<P>
<A NAME="1028974"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In the previous example, the variable <FONT FACE="courier, couriernew, monospaced size">myString</FONT> is a <FONT FACE="courier, couriernew, monospaced size">JavaObject</FONT> because it holds an instance of the Java object <FONT FACE="courier, couriernew, monospaced size">String</FONT>. As a <FONT FACE="courier, couriernew, monospaced size">JavaObject</FONT>, <FONT FACE="courier, couriernew, monospaced size">myString</FONT> has access to the public instance methods of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT> and its superclass, <FONT FACE="courier, couriernew, monospaced size">java.lang.Object</FONT>. These Java methods are available in JavaScript as methods of the <FONT FACE="courier, couriernew, monospaced size">JavaObject</FONT>, and you can call them as follows:</zparagraph>
</FONT>
<P>
<A NAME="1029015"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>myString.length() // returns 11
</zcodeline>
</FONT>
<P><P>
<BR>
<A NAME="1029016"> </A>
<A NAME="The Packages Object"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>The Packages Object</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1029407"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If a Java class is not part of the <FONT FACE="courier, couriernew, monospaced size">java</FONT>, <FONT FACE="courier, couriernew, monospaced size">sun</FONT>, or <FONT FACE="courier, couriernew, monospaced size">netscape</FONT> packages, you access it with the <FONT FACE="courier, couriernew, monospaced size">Packages</FONT> object. For example, suppose the Redwood corporation uses a Java package called <FONT FACE="courier, couriernew, monospaced size">redwood </FONT>to contain various Java classes that it implements. To create an instance of the <FONT FACE="courier, couriernew, monospaced size">HelloWorld</FONT> class in <FONT FACE="courier, couriernew, monospaced size">redwood</FONT>, you access the constructor of the class as follows:</zparagraph>
</FONT>
<P>
<A NAME="1029053"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>var red = new Packages.redwood.HelloWorld()
</zcodeline>
</FONT>
<P>
<A NAME="1029400"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You can also access classes in the default package (that is, classes that don't explicitly name a package). For example, if the HelloWorld class is directly in the <FONT FACE="courier, couriernew, monospaced size">CLASSPATH</FONT> and not in a package, you can access it as follows:</zparagraph>
</FONT>
<P>
<A NAME="1029401"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>var red = new Packages.HelloWorld()
</zcodeline>
</FONT>
<P>
<A NAME="1034409"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The LiveConnect <FONT FACE="courier, couriernew, monospaced size">java</FONT>, <FONT FACE="courier, couriernew, monospaced size">sun</FONT>, and <FONT FACE="courier, couriernew, monospaced size">netscape</FONT> objects provide shortcuts for commonly used Java packages. For example, you can use the following:</zparagraph>
</FONT>
<P>
<A NAME="1034421"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>var myString = new java.lang.String("Hello world")
</zcodeline>
</FONT>
<P>
<A NAME="1034419"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>instead of the longer version:</zparagraph>
</FONT>
<P>
<A NAME="1034430"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>var myString = new Packages.java.lang.String("Hello world")
</zcodeline>
</FONT>
<P><P>
<BR>
<A NAME="1029099"> </A>
<A NAME="Working with Java Arrays"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Working with Java Arrays</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1029044"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When any Java method creates an array and you reference that array in JavaScript, you are working with a <FONT FACE="courier, couriernew, monospaced size">JavaArray</FONT>. For example, the following code creates the <FONT FACE="courier, couriernew, monospaced size">JavaArray</FONT> <FONT FACE="courier, couriernew, monospaced size">x</FONT> with ten elements of type int:</zparagraph>
</FONT>
<P>
<A NAME="1029457"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>x = java.lang.reflect.Array.newInstance(java.lang.Integer, 10)
</zcodeline>
</FONT>
<P>
<A NAME="1029463"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Like the JavaScript <FONT FACE="courier, couriernew, monospaced size">Array</FONT> object, <FONT FACE="courier, couriernew, monospaced size">JavaArray</FONT> has a <FONT FACE="courier, couriernew, monospaced size">length</FONT> property which returns the number of elements in the array. Unlike <FONT FACE="courier, couriernew, monospaced size">Array.length</FONT>, <FONT FACE="courier, couriernew, monospaced size">JavaArray.length</FONT> is a read-only property, because the number of elements in a Java array are fixed at the time of creation.</zparagraph>
</FONT>
<P>
<P>
<BR>
<A NAME="1029045"> </A>
<A NAME="Package and Class References"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Package and Class References</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1029104"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Simple references to Java packages and classes from JavaScript create the <FONT FACE="courier, couriernew, monospaced size">JavaPackage</FONT> and <FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT> objects. In the earlier example about the Redwood corporation, for example, the reference <FONT FACE="courier, couriernew, monospaced size">Packages.redwood</FONT> is a <FONT FACE="courier, couriernew, monospaced size">JavaPackage</FONT> object. Similarly, a reference such as <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT> is a <FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT> object.</zparagraph>
</FONT>
<P>

<A NAME="1029184"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Most of the time, you don't have to worry about the <FONT FACE="courier, couriernew, monospaced size">JavaPackage</FONT> and <FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT> objects&#151;you just work with Java packages and classes, and LiveConnect creates these objects transparently.</zparagraph>
</FONT>
<P>

<A NAME="1034541"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In JavaScript 1.3 and earlier, <FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT> objects are not automatically converted to instances of <FONT FACE="courier, couriernew, monospaced size">java.lang.Class</FONT> when you pass them as parameters to Java methods&#151;you must create a wrapper around an instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.Class</FONT>. In the following example, the <FONT FACE="courier, couriernew, monospaced size">forName</FONT> method creates a wrapper object <FONT FACE="courier, couriernew, monospaced size">theClass</FONT>, which is then passed to the <FONT FACE="courier, couriernew, monospaced size">newInstance</FONT> method to create an array.</zparagraph>
</FONT>
<P>
<A NAME="1029248"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// JavaScript 1.3<br>
theClass = java.lang.Class.forName("java.lang.String")<br>
theArray = java.lang.reflect.Array.newInstance(theClass, 5)
</zcodeline>
</FONT>
<P>
<A NAME="1034437"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In JavaScript 1.4 and later, you can pass a <FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT> object directly to a method, as shown in the following example:</zparagraph>
</FONT>
<P>
<A NAME="1029368"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>// JavaScript 1.4<br>
theArray = java.lang.reflect.Array.newInstance(java.lang.String, 5)
</zcodeline>
</FONT>
<P><P>
<BR>
<A NAME="1029446"> </A>
<A NAME="Arguments of Type char"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Arguments of Type char</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1029456"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In JavaScript 1.4 and later, you can pass a one-character string to a Java method which requires an argument of type <FONT FACE="courier, couriernew, monospaced size">char</FONT>. For example, you can pass the string "H" to the <FONT FACE="courier, couriernew, monospaced size">Character</FONT> constructor as follows:</zparagraph>
</FONT>
<P>
<A NAME="1029552"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>c = new java.lang.Character("H")
</zcodeline>
</FONT>
<P>
<A NAME="1029503"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In JavaScript 1.3 and earlier, you must pass such methods an integer which corresponds to the Unicode value of the character. For example, the following code also assigns the value "H" to the variable <FONT FACE="courier, couriernew, monospaced size">c</FONT>:</zparagraph>
</FONT>
<P>
<A NAME="1029579"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>c = new java.lang.Character(72)
</zcodeline>
</FONT>
<P><P>
<BR>
<A NAME="1033594"> </A>
<A NAME="Handling Java Exceptions in JavaScript"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Handling Java Exceptions in JavaScript</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1033730"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When Java code fails at run time, it throws an exception. If your JavaScript code accesses a Java data member or method and fails, the Java exception is passed on to JavaScript for you to handle. Beginning with JavaScript 1.4, you can catch this exception in a <FONT FACE="courier, couriernew, monospaced size">try...catch</FONT> statement.</zparagraph>
</FONT>
<P>

<A NAME="1033740"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, suppose you are using the Java <FONT FACE="courier, couriernew, monospaced size">forName</FONT> method to assign the name of a Java class to a variable called <FONT FACE="courier, couriernew, monospaced size">theClass</FONT>. The <FONT FACE="courier, couriernew, monospaced size">forName</FONT> method throws an exception if the value you pass it does not evaluate to the name of a Java class. Place the <FONT FACE="courier, couriernew, monospaced size">forName</FONT> assignment statement in a <FONT FACE="courier, couriernew, monospaced size">try</FONT> block to handle the exception, as follows:</zparagraph>
</FONT>
<P>
<A NAME="1033838"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>function getClass(javaClassName) {<br>
&nbsp;&nbsp;&nbsp;try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var theClass = java.lang.Class.forName(javaClassName);<br>
&nbsp;&nbsp;&nbsp;} catch (e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ("The Java exception is " + e);<br>
&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;return theClass<br>
}
</zcodeline>
</FONT>
<P>
<A NAME="1033839"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In this example, if <FONT FACE="courier, couriernew, monospaced size">javaClassName</FONT> evaluates to a legal class name, such as "java.lang.String", the assignment succeeds. If <FONT FACE="courier, couriernew, monospaced size">javaClassName</FONT> evaluates to an invalid class name, such as "String", the <FONT FACE="courier, couriernew, monospaced size">getClass</FONT> function catches the exception and returns something similar to the following:</zparagraph>
</FONT>
<P>
<A NAME="1033779"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>The Java exception is java.lang.ClassNotFoundException: String
</zcodeline>
</FONT>
<P>
<A NAME="1033855"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>See <A HREF="stmtsov.html#1011537"  >"Exception Handling Statements" on page&nbsp;78</A> for more information about JavaScript exceptions.</zparagraph>
</FONT>
<P>

<BR>
<BR>

<A NAME="1008480"> </A>
<A NAME="Java to JavaScript Communication"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>Java to JavaScript Communication</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1030429"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If you want to use JavaScript objects in Java, you must import the <FONT FACE="courier, couriernew, monospaced size">netscape.javascript</FONT> package into your Java file. This package defines the following classes:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1030342"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSObject</FONT> allows Java code to access JavaScript methods and properties.</zsmartlist1>
</FONT>
<P><A NAME="1030343"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSException</FONT> allows Java code to handle JavaScript errors.</zsmartlist1>
</FONT>
<P></ul>

<A NAME="1030345"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><FONT FACE="courier, couriernew, monospaced size"></FONT>Starting with JavaScript 1.2, these classes are delivered in a .jar file; in previous versions of JavaScript, these classes are delivered in a .zip file. See the <A HREF="http://developer.netscape.com/docs/manuals/js/core/jsref/index.htm"><I>Core JavaScript Reference</I></A> for more information about these classes.</zparagraph>
</FONT>
<P>

<A NAME="1030361"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>To access the LiveConnect classes, place the .jar or .zip file in the <FONT FACE="courier, couriernew, monospaced size">CLASSPATH</FONT> of the JDK compiler in either of the following ways:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1030362"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Create a <FONT FACE="courier, couriernew, monospaced size">CLASSPATH</FONT> environment variable to specify the path and name of .jar or .zip file.</zsmartlist1>
</FONT>
<P><A NAME="1030363"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Specify the location of .jar or .zip file when you compile by using the <FONT FACE="courier, couriernew, monospaced size">-classpath</FONT> command line parameter.</zsmartlist1>
</FONT>
<P></ul>

<A NAME="1030364"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, in Navigator 4. 0 for Windows NT, the classes are delivered in the <FONT FACE="courier, couriernew, monospaced size">java40.jar</FONT> file in the <FONT FACE="courier, couriernew, monospaced size">Program\Java\Classes</FONT> directory beneath the Navigator directory. You can specify an environment variable in Windows NT by double-clicking the System icon in the Control Panel and creating a user environment variable called <FONT FACE="courier, couriernew, monospaced size">CLASSPATH</FONT> with a value similar to the following:</zparagraph>
</FONT>
<P>
<A NAME="1030365"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>D:\Navigator\Program\Java\Classes\java40.jar
</zcodeline>
</FONT>
<P>
<A NAME="1030366"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>See the Sun JDK documentation for more information about <FONT FACE="courier, couriernew, monospaced size">CLASSPATH</FONT>.</zparagraph>
</FONT>
<P>

<A NAME="1037485"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<znote>Note</znote>
</B>
</FONT>


<A NAME="1037486"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Because Java is a strongly typed language and JavaScript is weakly typed, the JavaScript runtime engine converts argument values into the appropriate data types for the other language when you use LiveConnect. See <A HREF="lc.html#1037078"  >Data Type Conversions</A> for complete information.</zparagraph>
</FONT>
<P>
<P>
<BR>
<A NAME="1030717"> </A>
<A NAME="Using the LiveConnect Classes"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Using the LiveConnect Classes</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1030718"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>All JavaScript objects appear within Java code as instances of <FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSObject</FONT>. When you call a method in your Java code, you can pass it a JavaScript object as one of its argument. To do so, you must define the corresponding formal parameter of the method to be of type <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT>.</zparagraph>
</FONT>
<P>

<A NAME="1032274"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Also, any time you use JavaScript objects in your Java code, you should put the call to the JavaScript object inside a <FONT FACE="courier, couriernew, monospaced size">try...catch</FONT> statement which handles exceptions of type <FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSException</FONT>. This allows your Java code to handle errors in JavaScript code execution which appear in Java as exceptions of type <FONT FACE="courier, couriernew, monospaced size">JSException</FONT>.</zparagraph>
</FONT>
<P>
<BR>
<P>
<A NAME="1032291"> </A>
<A NAME="Accessing JavaScript with JSObject"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>Accessing JavaScript with JSObject</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1031091"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, suppose you are working with the Java class called <FONT FACE="courier, couriernew, monospaced size">JavaDog</FONT>. As shown in the following code, the <FONT FACE="courier, couriernew, monospaced size">JavaDog</FONT> constructor takes the JavaScript object <FONT FACE="courier, couriernew, monospaced size">jsDog</FONT>, which is defined as type <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT>, as an argument:</zparagraph>
</FONT>
<P>
<A NAME="1031092"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>import netscape.javascript.*;<br>
<br>
public class JavaDog<br>
{<br>
&nbsp;&nbsp;&nbsp;&nbsp;public String dogBreed;<br>
&nbsp;&nbsp;&nbsp;&nbsp;public String dogColor;<br>
&nbsp;&nbsp;&nbsp;&nbsp;public String dogSex;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;// define the class constructor<br>
&nbsp;&nbsp;&nbsp;&nbsp;public JavaDog(JSObject jsDog)<br>
&nbsp;&nbsp;&nbsp;&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// use try...catch to handle JSExceptions here<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.dogBreed = (String)jsDog.getMember("breed");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.dogColor = (String)jsDog.getMember("color");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.dogSex = (String)jsDog.getMember("sex");<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}
</zcodeline>
</FONT>
<P>
<A NAME="1031093"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Notice that the <FONT FACE="courier, couriernew, monospaced size">getMember</FONT> method of <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT> is used to access the properties of the JavaScript object. The previous example uses <FONT FACE="courier, couriernew, monospaced size">getMember</FONT> to assign the value of the JavaScript property <FONT FACE="courier, couriernew, monospaced size">jsDog.breed</FONT> to the Java data member <FONT FACE="courier, couriernew, monospaced size">JavaDog.dogBreed</FONT>.</zparagraph>
</FONT>
<P>

<A NAME="1034579"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<znote>Note</znote>
</B>
</FONT>


<A NAME="1034585"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>A more realistic example would place the call to <FONT FACE="courier, couriernew, monospaced size">getMember</FONT> inside a <FONT FACE="courier, couriernew, monospaced size">try...catch</FONT> statement to handle errors of type <FONT FACE="courier, couriernew, monospaced size">JSException</FONT>. See <A HREF="lc.html#1032268"  >Handling JavaScript Exceptions in Java</A> for more information.</zparagraph>
</FONT>
<P>

<A NAME="1030728"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>To get a better sense of how <FONT FACE="courier, couriernew, monospaced size">getMember</FONT> works, look at the definition of the custom JavaScript object <FONT FACE="courier, couriernew, monospaced size">Dog</FONT>:</zparagraph>
</FONT>
<P>
<A NAME="1030740"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>function Dog(breed,color,sex) {<br>
&nbsp;&nbsp;&nbsp;this.breed = breed<br>
&nbsp;&nbsp;&nbsp;this.color = color<br>
&nbsp;&nbsp;&nbsp;this.sex = sex<br>
}
</zcodeline>
</FONT>
<P>
<A NAME="1030731"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You can create a JavaScript instance of <FONT FACE="courier, couriernew, monospaced size">Dog</FONT> called <FONT FACE="courier, couriernew, monospaced size">gabby</FONT> as follows:</zparagraph>
</FONT>
<P>
<A NAME="1030787"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>gabby = new Dog("lab","chocolate","female")
</zcodeline>
</FONT>
<P>
<A NAME="1030729"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If you evaluate <FONT FACE="courier, couriernew, monospaced size">gabby.color</FONT>, you can see that it has the value "chocolate". Now suppose you create an instance of <FONT FACE="courier, couriernew, monospaced size">JavaDog</FONT> in your JavaScript code by passing the <FONT FACE="courier, couriernew, monospaced size">gabby</FONT> object to the constructor as follows:</zparagraph>
</FONT>
<P>
<A NAME="1031134"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>javaDog = new Packages.JavaDog(gabby)
</zcodeline>
</FONT>
<P>
<A NAME="1030809"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If you evaluate <FONT FACE="courier, couriernew, monospaced size">javaDog.dogColor</FONT>, you can see that it also has the value "chocolate", because the <FONT FACE="courier, couriernew, monospaced size">getMember</FONT> method in the Java constructor assigns <FONT FACE="courier, couriernew, monospaced size">dogColor</FONT> the value of <FONT FACE="courier, couriernew, monospaced size">gabby.color</FONT>.</zparagraph>
</FONT>
<P>
<BR>
<P>
<A NAME="1032268"> </A>
<A NAME="Handling JavaScript Exceptions in Java"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>Handling JavaScript Exceptions in Java</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1035833"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When JavaScript code called from Java fails at run time, it throws an exception. If you are calling the JavaScript code from Java, you can catch this exception in a <FONT FACE="courier, couriernew, monospaced size">try...catch</FONT> statement. The JavaScript exception is available to your Java code as an instance of <FONT FACE="courier, couriernew, monospaced size">netscape.javascript</FONT>.<FONT FACE="courier, couriernew, monospaced size">JSException.</FONT></zparagraph>
</FONT>
<P>

<A NAME="1032650"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><FONT FACE="courier, couriernew, monospaced size">JSException</FONT> is a Java wrapper around any exception type thrown by JavaScript, similar to the way that instances of <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT> are wrappers for JavaScript objects. Use <FONT FACE="courier, couriernew, monospaced size">JSException</FONT> when you are evaluating JavaScript code in Java.</zparagraph>
</FONT>
<P>

<A NAME="1037855"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you are evaluating JavaScript code in Java, the following situations can cause run-time errors:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1037929"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>The JavaScript code is not evaluated, either due to a JavaScript compilation error or to some other error that occurred at run time.</zsmartlist1>
</FONT>
<P>  <dl>
     <DT> <A NAME="1037930"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>The JavaScript interpreter generates an error message that is converted into an instance of <FONT FACE="courier, couriernew, monospaced size">JSException</FONT>.</zparaindent1>
</FONT>
<P>  </dl>
<A NAME="1037856"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Java successfully evaluates the JavaScript code, but the JavaScript code executes an unhandled <FONT FACE="courier, couriernew, monospaced size">throw</FONT> statement.</zsmartlist1>
</FONT>
<P>  <dl>
     <DT> <A NAME="1037893"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>JavaScript throws an exception that is wrapped as an instance of <FONT FACE="courier, couriernew, monospaced size">JSException</FONT>. Use the <FONT FACE="courier, couriernew, monospaced size">getWrappedException</FONT> method of <FONT FACE="courier, couriernew, monospaced size">JSException</FONT> to unwrap this exception in Java.</zparaindent1>
</FONT>
<P>  </dl>
</ul>

<A NAME="1037944"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, suppose the Java object <FONT FACE="courier, couriernew, monospaced size">eTest</FONT> evaluates the string <FONT FACE="courier, couriernew, monospaced size">jsCode</FONT> that you pass to it. You can respond to either type of run-time error the evaluation causes by implementing an exception handler such as the following:</zparagraph>
</FONT>
<P>
<A NAME="1037945"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>import netscape.javascript.JSObject;<br>
import netscape.javascript.JSException;<br>
<br>
public class eTest {<br>
&nbsp;&nbsp;&nbsp;&nbsp;public static Object doit(JSObject obj, String jsCode) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj.eval(jsCode);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (JSException e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (e.getWrappedException()==null)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return e;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return e.getWrappedException();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return null;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}
</zcodeline>
</FONT>
<P>
<A NAME="1037953"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In this example, the code in the <FONT FACE="courier, couriernew, monospaced size">try</FONT> block attempts to evaluate the string <FONT FACE="courier, couriernew, monospaced size">jsCode</FONT> that you pass to it. Let's say you pass the string "<FONT FACE="courier, couriernew, monospaced size">myFunction()</FONT>" as the value of <FONT FACE="courier, couriernew, monospaced size">jsCode</FONT>. If <FONT FACE="courier, couriernew, monospaced size">myFunction</FONT> is not defined as a JavaScript function, the JavaScript interpreter cannot evaluate <FONT FACE="courier, couriernew, monospaced size">jsCode.</FONT> The interpreter generates an error message, the Java handler catches the message, and the <FONT FACE="courier, couriernew, monospaced size">doit</FONT> method returns an instance of <FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSException</FONT>.</zparagraph>
</FONT>
<P>

<A NAME="1038295"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>However, suppose <FONT FACE="courier, couriernew, monospaced size">myFunction</FONT> is defined in JavaScript as follows:</zparagraph>
</FONT>
<P>
<A NAME="1038296"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>function myFunction() {<br>
&nbsp;&nbsp;&nbsp;try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (theCondition == true) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return "Everything's ok";<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw "JavaScript error occurred" ;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;} catch (e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (canHandle == true) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handleIt();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw e;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;}<br>
}
</zcodeline>
</FONT>
<P>
<A NAME="1038297"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>If <FONT FACE="courier, couriernew, monospaced size">theCondition</FONT> is false, the function throws an exception. The exception is caught in the JavaScript code, and if <FONT FACE="courier, couriernew, monospaced size">canHandle</FONT> is true, JavaScript handles it. If <FONT FACE="courier, couriernew, monospaced size">canHandle</FONT> is false, the exception is rethrown, the Java handler catches it, and the <FONT FACE="courier, couriernew, monospaced size">doit</FONT> method returns a Java string:</zparagraph>
</FONT>
<P>
<A NAME="1038298"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>JavaScript error occurred
</zcodeline>
</FONT>
<P>
<A NAME="1032322"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>See <A HREF="stmtsov.html#1011537"  >"Exception Handling Statements" on page&nbsp;78</A> for complete information about JavaScript exceptions.</zparagraph>
</FONT>
<P>
<BR>
<P>
<A NAME="1037659"> </A>
<A NAME="Backward Compatibility"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<zhead4>Backward Compatibility</zhead4>
</B>
</FONT>
<BR>

<A NAME="1037778"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In JavaScript 1.3 and earlier versions, the <FONT FACE="courier, couriernew, monospaced size">JSException</FONT> class had three public constructors which optionally took a string argument, specifying the detail message or other information for the exception. The <FONT FACE="courier, couriernew, monospaced size">getWrappedException</FONT> method was not available.</zparagraph>
</FONT>
<P>

<A NAME="1037664"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Use a <FONT FACE="courier, couriernew, monospaced size">try...catch</FONT> statement such as the following to handle LiveConnect exceptions in JavaScript 1.3 and earlier versions:</zparagraph>
</FONT>
<P>
<A NAME="1037674"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>try {<br>
&nbsp;&nbsp;&nbsp;global.eval("foo.bar = 999;");<br>
} catch (Exception e) {<br>
&nbsp;&nbsp;&nbsp;if (e instanceof JSException) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jsCodeFailed()";<br>
&nbsp;&nbsp;&nbsp;} else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;otherCodeFailed();<br>
&nbsp;&nbsp;&nbsp;}<br>
}
</zcodeline>
</FONT>
<P>
<A NAME="1037731"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In this example, the <FONT FACE="courier, couriernew, monospaced size">eval</FONT> statement fails if <FONT FACE="courier, couriernew, monospaced size">foo</FONT> is not defined. The <FONT FACE="courier, couriernew, monospaced size">catch</FONT> block executes the <FONT FACE="courier, couriernew, monospaced size">jsCodeFailed</FONT> method if the <FONT FACE="courier, couriernew, monospaced size">eval</FONT> statement in the <FONT FACE="courier, couriernew, monospaced size">try</FONT> block throws a <FONT FACE="courier, couriernew, monospaced size">JSException</FONT>; the <FONT FACE="courier, couriernew, monospaced size">otherCodeFailed</FONT> method executes if the <FONT FACE="courier, couriernew, monospaced size">try</FONT> block throws any other error.</zparagraph>
</FONT>
<P>

<BR>
<BR>

<A NAME="1037078"> </A>
<A NAME="Data Type Conversions"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead1>Data Type Conversions</zhead1>
<HR SIZE="2" NOSHADE>
</FONT>
<BR>


<A NAME="1037079"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Because Java is a strongly typed language and JavaScript is weakly typed, the JavaScript runtime engine converts argument values into the appropriate data types for the other language when you use LiveConnect. These conversions are described in the following sections:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1037083"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037090"  >JavaScript to Java Conversions</A></zsmartlist1>
</FONT>
<P><A NAME="1037087"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037422"  >Java to JavaScript Conversions</A></zsmartlist1>
</FONT>
<P></ul>
<P>
<BR>
<A NAME="1037090"> </A>
<A NAME="JavaScript to Java Conversions"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>JavaScript to Java Conversions</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1037091"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you call a Java method and pass it parameters from JavaScript, the data types of the parameters you pass in are converted according to the rules described in the following sections:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1037095"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037125"  >Number Values</A></zsmartlist1>
</FONT>
<P><A NAME="1037099"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037169"  >Boolean Values</A></zsmartlist1>
</FONT>
<P><A NAME="1037103"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037205"  >String Values</A></zsmartlist1>
</FONT>
<P><A NAME="1037107"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037248"  >Undefined Values</A></zsmartlist1>
</FONT>
<P><A NAME="1037111"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037281"  >Null Values</A></zsmartlist1>
</FONT>
<P><A NAME="1037115"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037309"  >JavaArray and JavaObject objects</A></zsmartlist1>
</FONT>
<P><A NAME="1037119"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037349"  >JavaClass objects</A></zsmartlist1>
</FONT>
<P><A NAME="1037123"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><A HREF="lc.html#1037380"  >Other JavaScript objects</A></zsmartlist1>
</FONT>
<P></ul>

<A NAME="1037595"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The return values of methods of <FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSObject</FONT> are always converted to instances of <FONT FACE="courier, couriernew, monospaced size">java.lang.Object</FONT>. The rules for converting these return values are also described in these sections.</zparagraph>
</FONT>
<P>

<A NAME="1037627"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, if <FONT FACE="courier, couriernew, monospaced size">JSObject.eval</FONT> returns a JavaScript number, you can find the rules for converting this number to an instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.Object</FONT> in <A HREF="lc.html#1037125"  >Number Values</A>.</zparagraph>
</FONT>
<P>
<BR>
<P>
<A NAME="1037125"> </A>
<A NAME="Number Values"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>Number Values</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037126"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you pass JavaScript number types as parameters to Java methods, Java converts the values according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037166"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037129"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037131"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037133"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>double</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037135"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The exact value is transferred to Java without rounding and without a loss of magnitude or sign.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037137"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">lava.lang.Double<br>java.lang.Object</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037140"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A new instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.Double</FONT> is created, and the exact value is transferred to Java without rounding and without a loss of magnitude or sign.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037142"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>float</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP><ul>
<A NAME="1037144"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Values are rounded to float precision.</zsmartlist1>
</FONT>
<P><A NAME="1037145"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Values which are too large or small to be represented are rounded to +infinity or -infinity.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037147"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>byte<br>char<br>int<br>long<br>short</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP><ul>
<A NAME="1037153"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Values are rounded using round-to-negative-infinity mode.</zsmartlist1>
</FONT>
<P><A NAME="1037154"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Values which are too large or small to be represented result in a run-time error.</zsmartlist1>
</FONT>
<P><A NAME="1037155"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1><FONT FACE="courier, couriernew, monospaced size">NaN</FONT> values are converted to zero.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037157"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037159"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Values are converted to strings. For example,</ztabletext>
</FONT><ul>
<A NAME="1037160"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>237 becomes "237"</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037162"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP><ul>
<A NAME="1037164"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>0 and <FONT FACE="courier, couriernew, monospaced size">NaN</FONT> values are converted to false.</zsmartlist1>
</FONT>
<P><A NAME="1037165"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Other values are converted to true.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>


<A NAME="1037167"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When a JavaScript number is passed as a parameter to a Java method which expects an instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT>, the number is converted to a string. Use the <FONT FACE="courier, couriernew, monospaced size">equals()</FONT> method to compare the result of this conversion with other string values.</zparagraph>
</FONT>
<P>
<BR>
<P>
<A NAME="1037169"> </A>
<A NAME="Boolean Values"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>Boolean Values</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037170"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you pass JavaScript Boolean types as parameters to Java methods, Java converts the values according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037202"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037173"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037175"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037177"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037179"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>All values are converted directly to the Java equivalents.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037181"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">lava.lang.Boolean<br>java.lang.Object</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037184"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>A new instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.Boolean</FONT> is created. Each parameter creates a new instance, not one instance with the same primitive value.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037525"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037527"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Values are converted to strings. For example:</ztabletext>
</FONT><ul>
<A NAME="1037528"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>true becomes "true"</zsmartlist1>
</FONT>
<P><A NAME="1037529"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>false becomes "false"</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037186"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>byte<br>char<br>double<br>float<br>int<br>long<br>short</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP><ul>
<A NAME="1037194"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>true becomes 1</zsmartlist1>
</FONT>
<P><A NAME="1037195"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>false becomes 0</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>


<A NAME="1037203"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When a JavaScript Boolean is passed as a parameter to a Java method which expects an instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT>, the Boolean is converted to a string. Use the == operator to compare the result of this conversion with other string values.</zparagraph>
</FONT>
<P>
<BR>
<P>
<A NAME="1037205"> </A>
<A NAME="String Values"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>String Values</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037206"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you pass JavaScript string types as parameters to Java methods, Java converts the values according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037246"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037209"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037211"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037534"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">lava.lang.String<br>java.lang.Object</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037537"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>JavaScript 1.4:</ztabletext>
</FONT><ul>
<A NAME="1037538"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>A JavaScript string is converted to an instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT> with a Unicode value.</zsmartlist1>
</FONT>
<P></ul>

<P>
<A NAME="1037539"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1040801"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>JavaScript 1.3 and earlier:</ztabletext>
</FONT><ul>
<A NAME="1037540"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>A JavaScript string is converted to an instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT> with an ASCII value.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037546"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>byte<br>double<br>float<br>int<br>long<br>short</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037553"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>All values are converted to numbers as described in <A HREF="http://developer.netscape.com/docs/javascript/e262-pdf.pdf">ECMA-262</A>.</ztabletext>
</FONT>
<P>
<A NAME="1046270"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The JavaScript string value is converted to a number according to the rules described in ECMA-262</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037559"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>char</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037561"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>JavaScript 1.4:</ztabletext>
</FONT><ul>
<A NAME="1037562"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>One-character strings are converted to Unicode characters.</zsmartlist1>
</FONT>
<P><A NAME="1037563"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>All other values are converted to numbers.</zsmartlist1>
</FONT>
<P></ul>

<P>
<A NAME="1037564"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1040802"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>JavaScript 1.3 and earlier:</ztabletext>
</FONT><ul>
<A NAME="1037565"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>All values are converted to numbers.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037213"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP><ul>
<A NAME="1037215"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>The empty string becomes false.</zsmartlist1>
</FONT>
<P><A NAME="1037216"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>All other values become true.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>

<BR>
<P>
<A NAME="1037248"> </A>
<A NAME="Undefined Values"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>Undefined Values</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037249"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you pass undefined JavaScript values as parameters to Java methods, Java converts the values according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037277"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037252"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037254"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037507"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">lava.lang.String<br>java.lang.Object</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037510"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The value is converted to an instance of java.lang.String whose value is the string "undefined".</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037256"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037258"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The value becomes false.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037516"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>double<br>float</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037519"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The value becomes <FONT FACE="courier, couriernew, monospaced size">NaN</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037265"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>byte<br>char<br>int<br>long<br>short</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037271"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The value becomes 0.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>


<A NAME="1037278"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The undefined value conversion is possible in JavaScript 1.3 and later versions only. Earlier versions of JavaScript do not support undefined values.</zparagraph>
</FONT>
<P>

<A NAME="1037279"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When a JavaScript undefined value is passed as a parameter to a Java method which expects an instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT>, the undefined value is converted to a string. Use the == operator to compare the result of this conversion with other string values.</zparagraph>
</FONT>
<P>
<BR>
<P>
<A NAME="1037281"> </A>
<A NAME="Null Values"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>Null Values</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037282"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you pass null JavaScript values as parameters to Java methods, Java converts the values according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037307"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037285"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037287"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037568"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Any class<br>Any interface type</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037571"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The value becomes null.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1042434"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>byte<br>char<br>double<br>float<br>int<br>long<br>short</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037581"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The value becomes 0.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037289"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037291"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The value becomes false.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>

<BR>
<P>
<A NAME="1037309"> </A>
<A NAME="JavaArray and JavaObject objects"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>JavaArray and JavaObject objects</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037310"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>In most situations, when you pass a JavaScript <FONT FACE="courier, couriernew, monospaced size">JavaArray</FONT> or <FONT FACE="courier, couriernew, monospaced size">JavaObject</FONT> as a parameter to a Java method, Java simply unwraps the object; in a few situations, the object is coerced into another data type according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037345"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037313"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037315"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037317"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>Any interface or class that is assignment-compatible with the unwrapped object.</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037319"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is unwrapped.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037321"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037323"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is unwrapped, the <FONT FACE="courier, couriernew, monospaced size">toString</FONT> method of the unwrapped Java object is called, and the result is returned as a new instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037325"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>byte<br>char<br>double<br>float<br>int<br>long<br>short</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037333"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is unwrapped, and either of the following situations occur:</ztabletext>
</FONT><ul>
<A NAME="1037334"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the unwrapped Java object has a <FONT FACE="courier, couriernew, monospaced size">doubleValue</FONT> method, the <FONT FACE="courier, couriernew, monospaced size">JavaArray</FONT> or <FONT FACE="courier, couriernew, monospaced size">JavaObject</FONT> is converted to the value returned by this method.</zsmartlist1>
</FONT>
<P><A NAME="1037335"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the unwrapped Java object does not have a <FONT FACE="courier, couriernew, monospaced size">doubleValue</FONT> method, an error occurs.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037337"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037339"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>In JavaScript 1.3 and later versions, the object is unwrapped and either of the following situations occur:</ztabletext>
</FONT><ul>
<A NAME="1037340"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object is null, it is converted to false.</zsmartlist1>
</FONT>
<P><A NAME="1037341"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object has any other value, it is converted to true.</zsmartlist1>
</FONT>
<P></ul>

<P>
<A NAME="1037342"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1040810"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>In JavaScript 1.2 and earlier versions, the object is unwrapped and either of the following situations occur:</ztabletext>
</FONT><ul>
<A NAME="1037343"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the unwrapped object has a booleanValue method, the source object is converted to the return value.</zsmartlist1>
</FONT>
<P><A NAME="1037344"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object does not have a booleanValue method, the conversion fails.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>


<A NAME="1037346"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>An interface or class is assignment-compatible with an unwrapped object if the unwrapped object is an instance of the Java parameter type. That is, the following statement must return true:</zparagraph>
</FONT>
<P>
<A NAME="1037347"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline><I>unwrappedObject</I> instanceof <I>parameterType
</I></zcodeline>
</FONT>
<P><BR>
<P>
<A NAME="1037349"> </A>
<A NAME="JavaClass objects"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>JavaClass objects</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037350"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you pass a JavaScript <FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT> object as a parameter to a Java method, Java converts the object according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037378"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037353"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037355"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037357"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.Class</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037359"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is unwrapped.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037361"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.JSObject<br>java.lang.Object</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037364"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The <FONT FACE="courier, couriernew, monospaced size">JavaClass</FONT> object is wrapped in a new instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.JSObject</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037366"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037368"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is unwrapped, the <FONT FACE="courier, couriernew, monospaced size">toString</FONT> method of the unwrapped Java object is called, and the result is returned as a new instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037370"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037372"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>In JavaScript 1.3 and later versions, the object is unwrapped and either of the following situations occur:</ztabletext>
</FONT><ul>
<A NAME="1037373"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object is null, it is converted to false.</zsmartlist1>
</FONT>
<P><A NAME="1037374"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object has any other value, it is converted to true.</zsmartlist1>
</FONT>
<P></ul>

<P>
<A NAME="1037375"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1040812"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>In JavaScript 1.2 and earlier versions, the object is unwrapped and either of the following situations occur:</ztabletext>
</FONT><ul>
<A NAME="1037376"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the unwrapped object has a booleanValue method, the source object is converted to the return value.</zsmartlist1>
</FONT>
<P><A NAME="1037377"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object does not have a booleanValue method, the conversion fails.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>

<BR>
<P>
<A NAME="1037380"> </A>
<A NAME="Other JavaScript objects"> </A>
<FONT FACE="Arial, Helvetica, sans-serif">
<B>
<zhead3>Other JavaScript objects</zhead3>
</B>
</FONT>
<BR>
<BR>

<A NAME="1037381"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When you pass any other JavaScript object as a parameter to a Java method, Java converts the object according to the rules described in the following table:</zparagraph>
</FONT>
<P>

<P>
<A NAME="1037419"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<BR>
<P>
<TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">
  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT>
<BR>
<BR>
  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037384"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Java parameter type</ztablehead>
</B>
</FONT>
</TH>
    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1037386"> </A>
<P ALIGN="LEFT">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>
<ztablehead>Conversion rules</ztablehead>
</B>
</FONT>
</TH>
  </DIV></TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037388"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.JSObject<br>java.lang.Object</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037391"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is wrapped in a new instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.JSObject</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037393"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext><FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT></ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037395"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is unwrapped, the <FONT FACE="courier, couriernew, monospaced size">toString</FONT> method of the unwrapped object is called, and the result is returned as a new instance of <FONT FACE="courier, couriernew, monospaced size">java.lang.String</FONT>.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037397"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>byte<br>char<br>double<br>float<br>int<br>long<br>short</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037405"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>The object is converted to a value using the logic of the <FONT FACE="courier, couriernew, monospaced size">ToPrimitive</FONT> operator described in <A HREF="http://developer.netscape.com/docs/javascript/e262-pdf.pdf">ECMA-262</A>. The <I>PreferredType</I> hint used with this operator is Number.</ztabletext>
</FONT>&nbsp;</TD>
  </TR>
  <TR>
    <TD VALIGN=TOP>
<P>
<A NAME="1037411"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>boolean</ztabletext>
</FONT>&nbsp;</TD>
    <TD VALIGN=TOP>
<P>
<A NAME="1037413"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>In JavaScript 1.3 and later versions, the object is unwrapped and either of the following situations occur:</ztabletext>
</FONT><ul>
<A NAME="1037414"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object is null, it is converted to false.</zsmartlist1>
</FONT>
<P><A NAME="1037415"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object has any other value, it is converted to true.</zsmartlist1>
</FONT>
<P></ul>

<P>
<A NAME="1037416"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext></ztabletext>
</FONT>
<P>
<A NAME="1040814"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<ztabletext>In JavaScript 1.2 and earlier versions, the object is unwrapped and either of the following situations occur:</ztabletext>
</FONT><ul>
<A NAME="1037417"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the unwrapped object has a booleanValue method, the source object is converted to the return value.</zsmartlist1>
</FONT>
<P><A NAME="1037418"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>If the object does not have a booleanValue method, the conversion fails.</zsmartlist1>
</FONT>
<P></ul>
&nbsp;</TD>
  </TR>
</TABLE>



<P>
</FONT>
<P>

<P>
<BR>
<A NAME="1037422"> </A>
<A NAME="Java to JavaScript Conversions"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="4">
<zhead2>Java to JavaScript Conversions</zhead2>
</FONT>
<BR>
<BR>



<A NAME="1037423"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Values passed from Java to JavaScript are converted as follows:</zparagraph>
</FONT>
<P>
<ul>
<A NAME="1037424"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Java byte, char, short, int, long, float, and double are converted to JavaScript numbers.</zsmartlist1>
</FONT>
<P><A NAME="1037425"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>A Java boolean is converted to a JavaScript boolean.</zsmartlist1>
</FONT>
<P><A NAME="1037426"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>An object of class <FONT FACE="courier, couriernew, monospaced size">netscape.javascript.JSObject</FONT> is converted to the original JavaScript object.</zsmartlist1>
</FONT>
<P><A NAME="1037427"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>Java arrays are converted to a JavaScript pseudo-Array object; this object behaves just like a JavaScript <FONT FACE="courier, couriernew, monospaced size">Array</FONT> object: you can access it with the syntax <FONT FACE="courier, couriernew, monospaced size">arrayName[index]</FONT> (where <FONT FACE="courier, couriernew, monospaced size">index</FONT> is an integer), and determine its length with <FONT FACE="courier, couriernew, monospaced size">arrayName.length</FONT>.</zsmartlist1>
</FONT>
<P><A NAME="1037428"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist1>A Java object of any other class is converted to a JavaScript wrapper, which can be used to access methods and fields of the Java object:</zsmartlist1>
</FONT>
<P>  <ul>
<A NAME="1037430"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist2><FONT FACE="courier, couriernew, monospaced size"></FONT>Converting this wrapper to a string calls the <FONT FACE="courier, couriernew, monospaced size">toString</FONT> method on the original object.</zsmartlist2>
</FONT>
<P><A NAME="1037432"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist2><FONT FACE="courier, couriernew, monospaced size"></FONT>Converting to a number calls the <FONT FACE="courier, couriernew, monospaced size">doubleValue</FONT> method, if possible, and fails otherwise.</zsmartlist2>
</FONT>
<P><A NAME="1037460"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist2><FONT FACE="courier, couriernew, monospaced size"></FONT>Converting to a boolean in JavaScript 1.3 and later versions returns false if the object is null, and true otherwise.</zsmartlist2>
</FONT>
<P><A NAME="1037434"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<B>  <li></B>
<zsmartlist2><FONT FACE="courier, couriernew, monospaced size"></FONT>Converting to a boolean in JavaScript 1.2 and earlier versions calls the <FONT FACE="courier, couriernew, monospaced size">booleanValue</FONT> method, if possible, and fails otherwise.</zsmartlist2>
</FONT>
<P>  </ul>
  <dl>
     <DT> <A NAME="1037436"> </A>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2">
<zparaindent1>Note that instances of java.lang.Double and java.lang.Integer are converted to JavaScript objects, not to JavaScript numbers. Similarly, instances of java.lang.String are also converted to JavaScript objects, not to JavaScript strings.</zparaindent1>
</FONT>
<P>  </dl>
</ul>

<A NAME="1037437"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Java <FONT FACE="courier, couriernew, monospaced size">String</FONT> objects also correspond to JavaScript wrappers. If you call a JavaScript method that requires a JavaScript string and pass it this wrapper, you'll get an error. Instead, convert the wrapper to a JavaScript string by appending the empty string to it, as shown here:</zparagraph>
</FONT>
<P>
<A NAME="1037438"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="2">
<zcodeline>var JavaString = JavaObj.methodThatReturnsAString();<br>
var JavaScriptString = JavaString + "";
</zcodeline>
</FONT>
<P>


   </BLOCKQUOTE>
</BOOKCONTENT>

<FOOTERCONTENT>
   <BLOCKQUOTE>
 <BR>
            <b><a href="partlc.html">
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Previous</a></FONT>&nbsp;&nbsp;&nbsp;&nbsp;</b>
<a href="contents.html">
<b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Contents</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="ix.html"><b><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">Index</a></FONT></b>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="glossary.html">
<b>
<FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#993300">
Next
</a>
</FONT>
</b>&nbsp;&nbsp;&nbsp;&nbsp;
        <HR NOSHADE SIZE="1">


   <font face="Arial, Helvetica, sans-serif" SIZE="1">

Copyright &#169; 2000 <a href="http://www.netscape.com">Netscape Communications Corp.</a> All rights reserved.</FONT>
   </BLOCKQUOTE>
   <FONT FACE="Arial, Helvetica, sans-serif" SIZE="1">
   <P ALIGN="RIGHT">Last Updated <B>September 28, 2000</B>
   </FONT>
   <BR>

</FOOTERCONTENT>

</MAINCONTENT>

</BODY>


</HTML>